import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_enjoy_plus/utils/TokenManager.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../utils/PromptAction.dart';

class HomeNav extends StatelessWidget {
  HomeNav({Key? key}) : super(key: key);
// 导航数据
  // 程序员 必须有一个能力 抽象出对象的能力  万物皆对象
  final List navList = [
    {
      'title': '我的房屋',
      'icon': 'assets/images/house_nav_icon@2x.png',
    },
    {
      'title': '我的报修',
      'icon': 'assets/images/repair_nav_icon@2x.png',
    },
    {
      'title': '访客登记',
      'icon': 'assets/images/visitor_nav_icon@2x.png',
    }
  ];
  Widget getBottom() {
    return Container(
      width: double.infinity,
      height: 200,
      color: Colors.red,
      child: Column(
        children: [
          Text('1'),
          Text('1'),
          Text('1'),
        ],
      ),
    );
  }

  List<Widget> _getChildren(BuildContext ctx) {
    List<Widget> children = [];
    for (int i = 0; i < navList.length; i++) {
      children.add(GestureDetector(
        onTap: () async {
          // PromptAction.Info('成功');
          //   ScaffoldMessenger.of(ctx).showSnackBar(
          //       SnackBar(content: Text('我通知你'), duration: Duration(seconds: 1)));
          // },
          // showBottomSheet(context: ctx, builder: (ctx) => getBottom());
          // final SharedPreferences pp = await SharedPreferences.getInstance();
          if (i == 0) {
            tokenManager.setToken('导航');
          } else if (i == 1) {
            // print(pp.getInt('money'));
            String token = await tokenManager.getToken();
            print(token);
          } else {
            tokenManager.removeToken();
          }
        },
        child: Column(
          children: [
            Image.asset(
              navList[i]['icon'],
              width: 35,
            ),
            Text(navList[i]['title'])
          ],
        ),
      ));
    }
    return children;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 10),
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: _getChildren(context),
      ),
    );
  }
}
